/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.banco.struts.controller;

import com.banco.bt.usuarios.services.UsuarioServices;
import com.banco.struts.model.vo.Usuario;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

/**
 *
 * @author docenteFI
 */
public class LoginAction extends Action {
     private static final String SUCCESS = "success";
      private static final String ERROR = "error";
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        LoginActionForm loginForm = (LoginActionForm) form;
        ActionErrors errors = new ActionErrors();
        
        try {
            if(loginForm.getDocumento() == null || loginForm.getDocumento().length() == 0){
                return mapping.findForward(ERROR);
                        
            }else{
                /*UsuarioServices services = new UsuarioServices();
                Usuario usuario = services.obtenerUsuario(loginForm.getDocumento(), loginForm.getPin());
               */
                Usuario usuario = new Usuario();
                request.getSession().setAttribute("usuarioConectado", usuario);
                return mapping.findForward(SUCCESS);
           }
        }
        catch(Exception ex) {
            ex.printStackTrace();
            request.getSession().removeAttribute("usuarioConectado");
             errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("error.message", ex.getMessage()));
            saveErrors(request, errors);
            
            return mapping.findForward(ERROR);
        }
    }
    
    
    
}
